<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item label="出货单号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['outBillNo']" placeholder="请输入出货单号"></a-input>
        </a-form-item>
        <a-form-item label="批次号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['sectionNo']" placeholder="请输入批次号"></a-input>
        </a-form-item>
        <!-- <a-form-item label="公司编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['companyCode']" placeholder="请输入公司编码"></a-input>
        </a-form-item> -->
        <!-- <a-form-item label="上传时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择上传时间" v-decorator="['uploadDate']" :trigger-change="true" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%"/>
        </a-form-item> -->
        <a-form-item label="物料标记" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['imgExgFlag']" placeholder="请输入物料标记"></a-input>
        </a-form-item>
        <a-form-item label="项号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['itemNo']" placeholder="请输入项号" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="内部料号" :labelCol="labelCol" :wrapperCol="wrapperCol">
        	<j-popup v-decorator="['material',validatorRules.materielCode]" :trigger-change="true" org-fields="id,materiel_code,product_name,product_code,gauge,unit,query2"
        	 dest-fields="materielId,material,materialName,productCode,materialGuige,orderUnit,clientCode" code="materiel_search" @callback="popupCallback" />
        </a-form-item>
        <a-form-item label="品名" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['materialName']" placeholder="请输入品名" disabled></a-input>
        </a-form-item>
        <a-form-item label="规格" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['materialGuige']" placeholder="请输入规格" disabled></a-input>
        </a-form-item>
        <a-form-item label="客户料号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['clientCode']" placeholder="请输入客户料号" disabled></a-input>
        </a-form-item>
        <a-form-item label="商品编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['productCode']" placeholder="请输入商品编码" disabled></a-input>
        </a-form-item>
        <a-form-item label="企业单价" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['price']" placeholder="请输入企业单价" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="企业总价" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['amount']" placeholder="请输入企业总价" style="width: 100%"/>
        </a-form-item>
        <!-- <a-form-item label="币制" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['curr']" placeholder="请输入币制"></a-input>
        </a-form-item> -->
        <!-- <a-form-item label="企业关键合并key" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['companyMergerKey']" placeholder="请输入企业关键合并key"></a-input>
        </a-form-item> -->
        <a-form-item label="出口日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['invoiceDate']" placeholder="请输入出口日期,不输入默认上传当天"></a-input>
        </a-form-item>
        <a-form-item label="板数" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['palletNum']" placeholder="请输入板数" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="件数" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['pcs']" placeholder="请输入件数" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="包装种类" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['wrap']" placeholder="请输入包装种类"></a-input>
        </a-form-item>
        <a-form-item label="箱号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['containerNo']" placeholder="请输入箱号"></a-input>
        </a-form-item>
        <a-form-item label="企业数量" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['qty']" placeholder="请输入企业数量" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="净重" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['netWeight']" placeholder="请输入净重" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="毛重" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['grossWeight']" placeholder="请输入毛重" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="上传状态" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['expApplyState']" placeholder="请输入上传状态"></a-input>
        </a-form-item>
        <!-- <a-form-item label="主表id" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['expMainId']" placeholder="请输入主表id"></a-input>
        </a-form-item> -->
        <a-form-item label="目的国" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['destinationCountry']" placeholder="请输入目的国"></a-input>
        </a-form-item>
        <a-form-item label="立方数" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['zextendItemField1']" placeholder="请输入立方数"></a-input>
        </a-form-item>
        <a-form-item label="客户/供应商" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['scmCoc']" placeholder="请输入客户/供应商"></a-input>
        </a-form-item>

      </a-form>
    </a-spin>
  </j-modal>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'
  import JDate from '@/components/jeecg/JDate'

  export default {
    name: "ExpApplyBillModal",
    components: {
      JDate,
    },
    props:{
      mainId:{
        type:String,
        required:false,
        default:''
      }
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/order/expApplyMain/addExpApplyBill",
          edit: "/order/expApplyMain/editExpApplyBill",
        }

      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'createBy','createTime','updateBy','updateTime','sysOrgCode','outBillNo','sectionNo','companyCode','uploadDate','imgExgFlag','itemNo','material','materialGuige','materialName','price','amount','curr','companyMergerKey','invoiceDate','palletNum','pcs','wrap','containerNo','qty','netWeight','grossWeight','expApplyState','expMainId','destinationCountry','zextendItemField1','scmCoc','clientCode','productCode'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            formData['expMainId'] = this.mainId
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }

        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'createBy','createTime','updateBy','updateTime','sysOrgCode','outBillNo','sectionNo','companyCode','uploadDate','imgExgFlag','itemNo','material','materialGuige','materialName','price','amount','curr','companyMergerKey','invoiceDate','palletNum','pcs','wrap','containerNo','qty','netWeight','grossWeight','expApplyState','expMainId','destinationCountry','zextendItemField1','scmCoc','clientCode','productCode'))
      },


    }
  }
</script>
